home *** CD-ROM | disk | FTP | other *** search
/ The Best of MacTutor - S…e Code for Volumes 1 to 5 / The Best of MacTutor - Source Code for Volume 1-5 (Wayzata Technology)(6031)(1990).bin / Source Code / #23 (Aug 87) / Dont panic source / DON'T PANIC main.c < prev    next >
C/C++ Source or Header  |  1987-04-19  |  5KB  |  252 lines

  1.  /*
  2.  
  3.         THIS PROGRAM WILL OPEN A NODE ON THE APPLE TALK NETWORK.
  4.         IT WILL THEN FIND ALL THE NODES OUT THERE.  IF THE USR
  5.         ENTERS A MESSAGE IN THE EDIT FIELD AND PRESSES "SEND" 
  6.         THE USR CAN ALSO OPEN A RECIEVING SOCKET FOR PACKETS SENT TO 
  7.         IT.
  8.         
  9.         
  10.         FILE:
  11.                 ATSIMPLE.C
  12.                 
  13.         BY:
  14.                 TY SHIPMAN
  15.         
  16.         DATE:
  17.                 FEBRUARY 28, 1987
  18.         
  19.         (C) Copyright 1987 Ty Shipman
  20.         All Rights Resereved.
  21.         This notice must appear in all copies.  Commerical use of
  22.         this code forbidden, without prior written
  23.         permission of the author.
  24.  
  25.                 
  26. */
  27.  
  28. #include "MacTypes.h"
  29. #include "DialogMgr.h"
  30. #include "EventMgr.h"
  31. #include "ControlMgr.h"
  32.  
  33. #include "DON'T PANIC.h"
  34.  
  35. /*    
  36.         THESE ARE ALL OF THE GLOBALS THAT ARE NEEDED TO RUN TO PROGRAM
  37. */
  38.  
  39. WindowPtr        myWindow;     /* points to the dialog window struct */
  40. EventRecord        myEvent;        /*the event that just happened*/
  41. Handle            NodeName;    /* a handle to the rsrc for the current name, usually set in Chooser */
  42.  
  43. main() 
  44. {
  45.  
  46.     InitGraf(&thePort);
  47.     InitFonts();
  48.     FlushEvents( everyEvent, 0 );
  49.     InitWindows();
  50.     InitMenus();
  51.     TEInit();
  52.     InitDialogs(0L);
  53.     InitCursor();
  54.     MaxApplZone();
  55.     
  56.  
  57.     if( !Setup() )
  58.         while (DEvent()) ;
  59.     
  60.     ExitToShell();
  61. }
  62.  
  63. Setup()
  64. {
  65.  
  66.     if( PutUpWindow() )            /* go and get window and put it up with all if */
  67.         return(1);
  68.             
  69.     return(0);
  70.     
  71. }
  72.  
  73.  
  74. PutUpWindow()
  75. {
  76.         /* this routine will put up the dialog specified and init all 
  77.             buttons to default condition.  It will also check to see if
  78.             the ports are configured for AppleTalk or not.
  79.         */
  80.  
  81.     ControlHandle        itemHand;
  82.     int                type;
  83.     Rect                SelBox;
  84.  
  85.     CouldDialog(DIALOG_ID);        /*read into memory*/
  86.     
  87.     myWindow = GetNewDialog(DIALOG_ID,NIL,(WindowPtr)-1);
  88.     
  89.     NodeName = GetResource('STR ', -16096);        /* the name of the unit set in chooser */
  90.     
  91.     LoadResource(NodeName);        /* this is the name of this station set in chooser */
  92.     
  93.     
  94.     SetPort(myWindow);        /* hook in quickdraw    */
  95.     
  96.     GetDItem(myWindow,DISPLAYB,&type,&itemHand,&SelBox);        /*    THE DISPALY BUTTON, NO ITEMS IN LIST YET */
  97.     HiliteControl(itemHand,255);        /*part 255, dim out*/
  98.  
  99.     GetDItem(myWindow,SENDB,&type,&itemHand,&SelBox);            /*  I DON'T KNOW WHOM TO SEND TO YET */
  100.     HiliteControl(itemHand,255);        /*part 255, dim out*/
  101.     
  102.     WindUpdate();                            /* do all the boxing necessary */
  103.     
  104.     if( ATCheck() )                    /* at this time get net stuff */    
  105.         return(1);
  106.         
  107.     ShowWindow(myWindow);            /*all of a sudden up*/
  108.     
  109.     return(0);
  110.     
  111.         
  112. }
  113.  
  114.  
  115.  
  116. DEvent() 
  117. {
  118.     WindowPtr        whichWindow;
  119.     int                item;
  120.     DialogPtr        theDialog;
  121.         
  122.     SystemTask();
  123.     
  124.     if (GetNextEvent(everyEvent, &myEvent)) 
  125.     {
  126.             switch (myEvent.what) 
  127.         {
  128.             case driverEvt:
  129.             case networkEvt:
  130.             {
  131.                 DoATNet(myEvent.message);    /* pass handle to param block of type ????*/
  132.                 break;
  133.             }
  134.             
  135.             case mouseDown:
  136.                 switch (FindWindow( myEvent.where, &whichWindow )) 
  137.                 {
  138.     
  139.                     case inGoAway:
  140.                         if (TrackGoAway( myWindow, myEvent.where) )
  141.                         {
  142.                             CloseAT();
  143.                             return(0);
  144.                         }
  145.                     break;
  146.                 
  147.                 }
  148.     
  149.         case updateEvt:
  150.         {
  151.             WindUpdate(); 
  152.             break;
  153.         }
  154.         
  155.  
  156.         default: ;
  157.         } /* end of case myEvent.what */
  158.         
  159.         IsDialogEvent(&myEvent);
  160.         
  161.         if( DialogSelect(&myEvent,&theDialog,&item) )
  162.             if( theDialog == myWindow)                    /* some DA's are Dialogs */
  163.                 DoATDialog(item);
  164.     } 
  165.  
  166.     else
  167.     {
  168.         IsDialogEvent(&myEvent);
  169.                                     /* so the caret blinks    */
  170.         DialogSelect(&myEvent,&theDialog,&item);
  171.     }
  172.     
  173.     return(1);
  174. }
  175.  
  176.  
  177.  
  178.  
  179. DoATDialog(item)
  180. int        item;            /*the item just hit*/
  181. {
  182.         /* this routine will respond to the item hit on the dialog */
  183.         
  184.         switch(item)
  185.         {
  186.         
  187.             case    LOOKB:
  188.             {
  189.                 
  190.                 LookUp();
  191.                 break;
  192.             }
  193.                         
  194.             case    DISPLAYB:
  195.             {                
  196.                 Display();
  197.                 break;
  198.             }
  199.         
  200.             case    SENDB:
  201.             {
  202.                 Send();
  203.                 break;
  204.             }
  205.             
  206.             
  207.             default:
  208.                 break;
  209.         }/*end switch*/
  210. }
  211.  
  212. WindUpdate()
  213. {    /* this routine will draw all the necessary stuff in the window when an
  214.         update occures
  215.     */
  216.     
  217.     ControlHandle        itemHand;
  218.     int                type;
  219.     Rect                SelBox;
  220.     
  221.     GetDItem(myWindow,RECM,&type,&itemHand,&SelBox);
  222.     InsetRect(&SelBox,-1,-1);    
  223.     FrameRect(&SelBox);                /* THE RECIEVED MESSAGE BOX */
  224.     
  225.  
  226.     GetDItem(myWindow,MYNODE,&type,&itemHand,&SelBox);
  227.     SetIText(itemHand,(*NodeName));            /* the name set is chooser */
  228.     FrameRect(&SelBox);                /* THE WHOM AM I FIELD */
  229.     
  230.     GetDItem(myWindow,MYNUM,&type,&itemHand,&SelBox);
  231.     InsetRect(&SelBox,-2,-2);    
  232.     FrameRect(&SelBox);                /* THE WHOM AM I node number FIELD */
  233.  
  234.     GetDItem(myWindow,SENDM,&type,&itemHand,&SelBox);
  235.     InsetRect(&SelBox,-2,-2);    
  236.     FrameRect(&SelBox);                /* THE WHOM AM I FIELD */
  237.     
  238.     GetDItem(myWindow,NUMBER,&type,&itemHand,&SelBox);
  239.     InsetRect(&SelBox,-2,-2);        
  240.     FrameRect(&SelBox);                /* THE NUMBER OF NODES/SOCKETS FIELD */
  241.  
  242.     GetDItem(myWindow,CNODEIS,&type,&itemHand,&SelBox);
  243.     InsetRect(&SelBox,-2,-2);        
  244.     FrameRect(&SelBox);                /* THE CURRENT NODE NUMBER FIELD */
  245.  
  246.     GetDItem(myWindow,CNODENUM,&type,&itemHand,&SelBox);
  247.     InsetRect(&SelBox,-2,-2);        
  248.     FrameRect(&SelBox);                /* THE CURRENT NAME OF THE NUMBER FIELD */
  249.     
  250. }
  251.  
  252.